//=============================================================================
// DirectInput.h by Frank Luna (C) 2005 All Rights Reserved.
//
// Wraps initialization of immediate mode Direct Input, and provides 
// information for querying the state of the keyboard and mouse.
//=============================================================================

#ifndef DIRECT_INPUT_H
#define DIRECT_INPUT_H

#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include "d3dUtil.h"
#include "Macro.h"

class DirectInput
{
public:
	DirectInput(DWORD keyboardCoopFlags, DWORD mouseCoopFlags);
	virtual ~DirectInput();
	
	static DirectInput* GetInstance() 
	{
		if(!s_pDirectInput) 
		{
			s_pDirectInput = new DirectInput(DISCL_NONEXCLUSIVE|DISCL_FOREGROUND, DISCL_NONEXCLUSIVE|DISCL_FOREGROUND);
		}
		return s_pDirectInput;
	}

	void Release()
	{
		SAFE_DEL(s_pDirectInput);
	}

	void poll();
	bool keyDown(unsigned char key);
	
    bool keyUp(unsigned char key);
    bool onKeyDown(unsigned char key);
	bool onKeyUp(unsigned char key);
   	std::vector<unsigned int> mPreKeyAray;
	int getIndexByKey(unsigned int key);

	bool mouseButtonDown(int button);
	float mouseDX();
	float mouseDY();
	float mouseDZ();
	DIMOUSESTATE2        mMouseState;
	IDirectInputDevice8* mMouse;
	char                 mKeyboardState[256]; 
	
	IDirectInputDevice8* mKeyboard;
private:
	
	// Make private to prevent copying of members of this class.
	DirectInput(const DirectInput& rhs);
	DirectInput& operator=(const DirectInput& rhs);

private:
	IDirectInput8*       mDInput;
	static DirectInput* s_pDirectInput;
};

#endif // DIRECT_INPUT_H